import 'package:flutter/material.dart';
import 'dart:math';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '每日灵感',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
        useMaterial3: true,
      ),
      home: const InspirationPage(title: '每日灵感'),
    );
  }
}

class InspirationPage extends StatefulWidget {
  const InspirationPage({super.key, required this.title});

  final String title;

  @override
  State<InspirationPage> createState() => _InspirationPageState();
}

class _InspirationPageState extends State<InspirationPage> {
  final List<String> _quotes = [
    "生活不是等待风暴过去，而是学会在雨中跳舞。",
    "成功不是最终的，失败也不是致命的，重要的是继续前进的勇气。",
    "不要等待机会，而要创造机会。",
    "每一个不曾起舞的日子，都是对生命的辜负。",
    "没有人可以回到过去重新开始，但谁都可以从今天开始，书写一个全然不同的结局。",
    "态度决定一切，细节决定成败。",
    "生活中最重要的事情是明确你想要什么，然后有勇气去追求它。",
    "不要因为没有掌声而放弃梦想，掌声会在梦想实现的那一刻响起。",
    "成功的秘诀是坚持目标的始终。",
    "人生就像一场马拉松，重要的不是瞬间的爆发，而是保持长久的耐力。"
  ];
  int _currentIndex = 0;
  final Random _random = Random();

  void _changeQuote() {
    setState(() {
      int newIndex;
      do {
        newIndex = _random.nextInt(_quotes.length);
      } while (newIndex == _currentIndex && _quotes.length > 1);
      _currentIndex = newIndex;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Column(
        children: [
          Expanded(
            child: Center(
              child: Padding(
                padding: const EdgeInsets.all(20.0),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Card(
                      elevation: 5,
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(15),
                      ),
                      child: Padding(
                        padding: const EdgeInsets.all(20.0),
                        child: Column(
                          children: [
                            const Icon(
                              Icons.format_quote,
                              size: 40,
                              color: Colors.blue,
                            ),
                            const SizedBox(height: 20),
                            Text(
                              _quotes[_currentIndex],
                              style: const TextStyle(
                                fontSize: 22,
                                fontWeight: FontWeight.w500,
                              ),
                              textAlign: TextAlign.center,
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
          Container(
            padding: const EdgeInsets.all(16),
            alignment: Alignment.center,
            child: const Text(
              '杨信+20221060046',
              style: TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.bold,
              ),
            ),
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _changeQuote,
        tooltip: '查看新的灵感',
        child: const Icon(Icons.refresh),
      ),
    );
  }
}
